/**预警查看
 */
;
(function(){
'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('WarningViewIntegrityCtrl', ['$scope','$modal','$state','CaseCommonService','$http', 
	                                  '$stateParams','WarningAddService','BaseURL','Modal','WarningScreenService',
	    function ($scope,$modal,$state,CaseCommonService,$http,$stateParams,WarningAddService,baseUrl,Modal,WarningScreenService) {
		$scope.serv = WarningAddService;
		//预警编号
		var warnNo=$stateParams.warnNo,
			staffCode=[],
			insurCode=[],
		    screen=[];
		$scope.warningFrom={};
		$scope.warningFrom.date={};
		$scope.notice = {};
		$scope.resultNotice = {};
		$scope.warnInsurCount=0;
		$scope.warnStaffCount=0;
		$scope.warnMedicalCount=0;
		$scope.warnInsurData=[];
		$scope.warnStaffData=[];
		$scope.warnMedicalData={};
		$scope.warnScreenList=[];
		$scope.prcoessTypeFlag=false;
		$scope.resultNoticeShow=false;
		var actNo = $stateParams.actNo;//状态
		var processNo=$stateParams.processNo;//处理方式
		$scope.tabs = [];
		//------------------tab页显示设置-----------
		var pageOne = {name:'网上筛查',status:0,index:0,url:baseUrl+'views/hcpms/warning/warnView/warningViewScreen_view.html'};
		var pageTwo = {name:'自查结果',status:0,index:1,url:baseUrl+'views/hcpms/warning/warnView/warningSelfExamResult_view.html'};
		var pageThree = {name:'结果评估',status:0,index:2,url:baseUrl+'views/hcpms/warning/warnView/warningResultQuery_view.html'};
		var pageFour = {name:'复审意见',status:0,index:3,url:baseUrl+'views/hcpms/warning/warnView/warningQueryAudit_view.html'};
		var pageFive= {name:'审批意见',status:0,index:4,url:baseUrl+'views/hcpms/warning/warnView/warningQueryExamine_view.html'};
		var linkResult = function (){
			   $scope.isFlatOne = false;
			   $scope.isFlatTwo = false;
			   $scope.isFlatThree = false;
			   $scope.isFlatFour = false;
			   $scope.isFlatFive = false;
			   if(actNo == 'N2014001'
				   		|| actNo == 'N2014002'
				   		|| actNo == 'N2014003'
				   		|| actNo == 'N2014004'
				   		|| actNo == 'N2014005'){//1tab
				   $scope.isFlatOne = true; 
			   }else if(actNo == 'N2014006'){//2tab
				   $scope.isFlatOne = true;
				   $scope.isFlatTwo = true; 
			   }else if(actNo == 'N2014007'){//3tab
				   $scope.isFlatOne = true;
				   $scope.isFlatTwo = true;
				   $scope.isFlatThree = true;
			   }else if(actNo == 'N2014008'){//4tab
				   $scope.isFlatOne = true;
				   $scope.isFlatTwo = true;
				   $scope.isFlatThree = true;
				   $scope.isFlatFour = true;
			   }else if(actNo == 'N2014009'){//5tab
				   $scope.isFlatOne = true;
				   $scope.isFlatTwo = true;
				   $scope.isFlatThree = true;
				   $scope.isFlatFour = true;
				   $scope.isFlatFive = true;
			   }
		  }
		
			 var linkResultPage = function(){
					if($scope.isFlatOne){
						$scope.tabs.push(pageOne);
						$scope.isNumOne = 0;
						if($scope.isFlatTwo){
							$scope.tabTwoController = "";
							$scope.tabs.push(pageTwo);
							$scope.isNumTwo = 1;
							if($scope.isFlatThree){
								$scope.tabs.push(pageThree);
								$scope.isNumThree = 2;
								if($scope.isFlatFour){
									$scope.tabs.push(pageFour);
									$scope.isNumFour = 3;
									if($scope.isFlatFive){
										$scope.tabs.push(pageFive);
										$scope.isNumFive = 4;
									}
								}
							}
						}
					}
				}
			 //提醒、转稽核tab页筛选
		var linkResultFilter=function(){
			if(processNo=='01'||processNo=='03'||processNo=='05'){
				   $scope.isFlatOne = true;
				   $scope.isFlatTwo = false;
				   $scope.isFlatThree = false;
				   $scope.isFlatFour = false;
				   $scope.isFlatFive = false;
			}
		}
		
		//--------------------------------------------------------
		/**
		 * 显示附件
		 */
		$scope.path="";
		var params2 = {id:warnNo};
		CaseCommonService.showImage(params2).success(function(res){
			$scope.fileData = res.result.imgList;
		    $scope.path=res.path;
		});
	    
		//显示下载和查看按钮
		$scope.showId = "";
        $scope.mouseover=function(id)
        {
        	 $scope.showId = id;
        }
        
        /**
         * 下载文件
         */
        $scope.downLoadFile=function(item){
            var path="";
            var suffix = item.name.substring(0,item.name.lastIndexOf('.'));
            window.location = baseUrl + 'agreement/downloadFile.do?fileInfoId='+item.businessNo+'/insurance/'+suffix+
                '&fileName='+item.name+'&path='+path;
        }
        /**
         * 查看文件
         */
        $scope.openLoadFile=function(item){
            var path= $scope.path+'/'+item.businessNo+'/insurance/'+ item.name;
           var  param={filePath:path};
            $http.post(baseUrl + 'agreement/exitFile.do',param).success(function(data) {
                if(data.state!="error")
                {
                    window.open(baseUrl + '/file/openPdfFile.do?filePath='+path);
                }else
                {
                    Modal.alert(data.msg);
                }
            })
        }
	     //--------------------------------------------------------
		
		//退回时改变tab页的显示
		var changeLinkResultByCheckBack=function(){			
			if($scope.warningFrom&&$scope.warningFrom.isCheckBack=='1'){
				if(actNo == 'N2014003'){//改变tab1页面
					pageOne = {name:'网上筛查',status:0,index:0,url:baseUrl+'views/hcpms/warning/warnView/warningViewScreenBack_view.html'};
				}else if(actNo == 'N2014005'){//2tab
					$scope.isFlatOne = true;
					$scope.isFlatTwo = true; 
				}else if(actNo == 'N2014006'){//3tab
					   $scope.isFlatOne = true;
					   $scope.isFlatTwo = true;
					   $scope.isFlatThree = true;
					   $scope.isFlatFour = true;
				   }else if(actNo == 'N2014007'){//4tab
					   $scope.isFlatOne = true;
					   $scope.isFlatTwo = true;
					   $scope.isFlatThree = true;
					   $scope.isFlatFour = true;
					   $scope.isFlatFive = true;
				   }else if(actNo == 'N2014008'){//5tab
					   $scope.isFlatOne = true;
					   $scope.isFlatTwo = true;
					   $scope.isFlatThree = true;
					   $scope.isFlatFour = true;
					   $scope.isFlatFive = true;
				   }
			}
		}		 
		//--------------------------
		function queryWarning(){
			WarningAddService.getHcpmsWarning({warnNo:warnNo})
			.success(function(res){
					$scope.warningFrom=res.warnInfo;					
					if(res.warnStaffList){
						$scope.warnStaffData=res.warnStaffList;
						$scope.warnStaffCount=res.warnStaffList.length;
						angular.forEach($scope.warnStaffData,function(data,index){
							 if($.inArray(data.code, staffCode) === -1){
								 staffCode.push(data.code);
							 }
						 });
			         }
					if(res.warnInsuranceList){
						$scope.warnInsurData=res.warnInsuranceList;
						$scope.warnInsurCount=res.warnInsuranceList.length;
						angular.forEach($scope.warnInsurData,function(data,index){
							if($.inArray(data.code, insurCode) === -1){
								insurCode.push(data.code);
							 }
						 });
			          }
					if(res.warnScreenList){
						$scope.warnScreenList=res.warnScreenList;
						angular.forEach($scope.warnScreenList,function(data,index){
							screen.push(data.monitorNo+data.ruleNo);
						 });
					 }
					if(res.notice){
						$scope.notice=res.notice;
					}
					if(res.warnMedicalInfo){
	        			$scope.warnMedicalData=res.warnMedicalInfo;
	        			$scope.warnMedicalCount=1;
	        		}
					if($scope.warningFrom.process==='02'||$scope.warningFrom.process==='04'){
        				$scope.prcoessTypeFlag=true;
        				if(actNo == 'N2014009'||actNo == 'N2014008'){
        					$scope.resultNoticeShow=true;
					    }
        			}
					 linkResult();
					 linkResultFilter();
					 changeLinkResultByCheckBack();
					 linkResultPage();
					 $scope.currentTab = $scope.tabs.length-1;
						$scope.currentTabIndex=$scope.tabs.length-1;
						$scope.tabClick = function(index) {
							$scope.currentTab = index;
							$scope.currentTabIndex=index;
						}
					WarningScreenService.findPointCutTempScose(
			 				   WarningAddService.warningMarks,$stateParams.warnNo,'01',
			 				   $scope.warnMedicalData,$scope.warnStaffData,$scope.warnInsurData);
		     });			
		}
		queryWarning();
		//获取结果告知书
		function getNoticeDate(){
			WarningAddService.getWarnNotice({warnNo:warnNo})
			.success(function(res){
				if(res.resultNotice){
					$scope.resultNotice=res.resultNotice;
				}
			});
		}
		getNoticeDate();
		//查看案件来源
		$scope.viewDetailWarning = function(){
			var scope = $scope.$new();
			scope.warningFrom = $scope.warningFrom;
			var modalInstance = $modal.open({
	      	      templateUrl: baseUrl +'views/hcpms/warning/warnView/warningViewBase_view.html',
	      	      backdrop:'static',
				  size:'sm',
				  scope:scope,
	      	      controller:function($modalInstance,$scope){
					  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
	  	    });	
		}
		//自查通知书
		$scope.warningNoticeDialog = function() {
			var scope = $scope.$new();
			scope.warningNotice=$scope.notice;
			scope.warningNotice.date=WarningAddService.setPriodDate(scope.warningNotice.datestart,scope.warningNotice.dateend);
			
			var modalInstance = $modal.open({
	      	      templateUrl: baseUrl +'views/hcpms/warning/warnView/warningViewNotice_view.html',
	      	      backdrop:'static',
				  size:'sm',
				  scope:scope,
	      	      controller:function($modalInstance,$scope){
	      	    	 $scope.$watch('$viewContentLoaded',function(){
	      	    		downFile('03','warningViewNoticeOpenpdf');
	      	          });
	      	    	  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
	  	    });
		}
		//结果告知书
		$scope.warnResultToldDialog = function (){
			var scope = $scope.$new();
			scope.resultNotice=$scope.resultNotice;
			scope.resultNotice.resultNoticeDate = WarningAddService.setPriodDate($scope.resultNotice.startDate,$scope.resultNotice.endDate);
			var modalInstance = $modal.open({
	      	      templateUrl: baseUrl +'views/hcpms/warning/warnView/warningViewResultNotice_view.html',
	      	      backdrop:'static',
				  size:'sm',
				  scope:scope,
	      	      controller:function($modalInstance,$scope){
	      	    	 $scope.$watch('$viewContentLoaded',function(){
		      	    		downFile('02','warningViewResultNoticeOpenpdf');
		      	      });
	      	    	  $scope.onClose = function(){
				  		   $modalInstance.dismiss();
					  }
				}	
	  	    });
		}
		/*function downFile(param){
	    	window.location = baseUrl+'HcpmsWarnDownFile/downPdfFile.do?warnNo='+warnNo+'&docType='+param+'&warnNoBiz='+$scope.warningFrom.warnNoBiz;
		}*/
		
		/**打开PDF文件*/
		   function downFile(param,openpdfId){
		   		var success = new PDFObject({ url:baseUrl+'HcpmsWarnDownFile/downPdfFile.do?warnNo='+warnNo+'&docType='+param+'&warnNoBiz='+$scope.warningFrom.warnNoBiz,
					 pdfOpenParams: { 
						 navpanes: 1,
						 toolbar: 1,
						 statusbar: 1,
						 view: 'FitV',
						 pagemode: 'thumbs'
				     }
		   		}).embed(openpdfId);
		  }
		//查看参保人员详细信息
		$scope.viewInsurList = function(){
			var scope = $scope.$new();
			scope.warnInsuranceList=$scope.warnInsurData;
			var modalInstance = $modal.open({
			      templateUrl: baseUrl+'views/hcpms/warning/warnView/warningViewInsurance_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:function($modalInstance,$scope){
					  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
			    });
			
		}
		//查看医护人员详细信息
		$scope.viewStaffList = function(){
			var scope = $scope.$new();
			scope.warnStaffList=$scope.warnStaffData;
			var modalInstance = $modal.open({
				  templateUrl: baseUrl+'views/hcpms/warning/warnView/warningViewStaff_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:function($scope,$modalInstance){
		  	          //取消或或者直接关闭
					  $scope.onOk = function(){
						  $modalInstance.dismiss();
			          }	
				  }
			    });
			
		}
		//查看医疗机构详细信息
		$scope.viewMedicalInfo = function(){
            if(!$scope.warnMedicalData){
            	return;
            }
			var scope = $scope.$new();
			$scope.medical=$scope.warnMedicalData;
			var modalInstance = $modal.open({
				  templateUrl: baseUrl+'views/hcpms/warning/warnView/warningViewMedical_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:function($scope,$modalInstance){
		  	          //取消或或者直接关闭
					  $scope.onOk = function(){
						  $modalInstance.dismiss();
			          }	
				  }
			    });
			
		}
		//隐藏扣分以及删除按钮
		$scope.mouseoutShow = function(data){
			data.show = false;
		}
        //显示扣分以及删除按钮
		$scope.mouseoverShow = function(data){
			data.show = true;
		}
		
		//自查结果
		$scope.selfResult = {};
		$scope.selfResultList =[];
		function getSelfExamResult(){
			WarningAddService.getWarnCheckResult({warnNo:warnNo}).
			success(function(res){
				if(res.checkResults){
					$scope.selfResult = res.checkResults;
					$scope.selfResult.checkSumamount=parseFloat(res.checkResults.checkSumamount).toFixed(2);
				}
				if(res.detailList){
					$scope.selfResultList = res.detailList;
				}
			});
		}
		getSelfExamResult();
		/**自查结果评估**/
		$scope.assessResult={};
		$scope.assessResultList=[];
		function getAssessResult(){
			WarningAddService.getWarnResult({warnNo:warnNo}).
			success(function(res){
				if(res.warnResult){
					$scope.assessResult = res.warnResult;					
					$scope.assessResult.sumAmount=parseFloat(res.warnResult.sumAmount).toFixed(2);					
				}
				if(res.warnResultList){
					$scope.assessResultList = res.warnResultList;
				}
			});
		}
		getAssessResult();
		/**结论复审**/
		function getAuditResult(){
			WarningAddService.getAuditResult({warnNo:warnNo})
			.success(function(res){
				if(res.auditResult){
					$scope.auditResult=res.auditResult;	
				}
			});
		}
		getAuditResult();		
		//返回
	   $scope.backWarning = function(){
        	$state.go("integrityJump.warningIntegrityQuery",{
        	});
        }
	}]);
})();